package com.ruoyi.plot.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.plot.domain.AtbPlotDetail;
import com.ruoyi.plot.dto.request.StatusDto;
import com.ruoyi.plot.service.IAtbPlotDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 小区详情Controller
 * 
 * @author ruoyi
 * @date 2024-09-14
 */
@RestController
@RequestMapping("/plot/plot")
public class AtbPlotDetailController extends BaseController
{
    @Autowired
    private IAtbPlotDetailService atbPlotDetailService;

    /**
     * 查询小区详情列表
     */
    @PreAuthorize("@ss.hasPermi('plot:plot:list')")
    @GetMapping("/list")
    public TableDataInfo list(AtbPlotDetail atbPlotDetail)
    {
        startPage();
        List<AtbPlotDetail> list = atbPlotDetailService.selectAtbPlotDetailList(atbPlotDetail);
        return getDataTable(list);
    }

    /**
     * 导出小区详情列表
     */
    @PreAuthorize("@ss.hasPermi('plot:plot:export')")
    @Log(title = "小区详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AtbPlotDetail atbPlotDetail)
    {
        List<AtbPlotDetail> list = atbPlotDetailService.selectAtbPlotDetailList(atbPlotDetail);
        ExcelUtil<AtbPlotDetail> util = new ExcelUtil<AtbPlotDetail>(AtbPlotDetail.class);
        util.exportExcel(response, list, "小区详情数据");
    }

    /**
     * 获取小区详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('plot:plot:query')")
    @GetMapping(value = "/{plotId}")
    public AjaxResult getInfo(@PathVariable("plotId") Long plotId)
    {
        return success(atbPlotDetailService.selectAtbPlotDetailByPlotId(plotId));
    }

    /**
     * 新增小区详情
     */
    @PreAuthorize("@ss.hasPermi('plot:plot:add')")
    @Log(title = "小区详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AtbPlotDetail atbPlotDetail)
    {
        return toAjax(atbPlotDetailService.insertAtbPlotDetail(atbPlotDetail));
    }

    /**
     * 修改小区详情
     */
    @PreAuthorize("@ss.hasPermi('plot:plot:edit')")
    @Log(title = "小区详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AtbPlotDetail atbPlotDetail)
    {
        return toAjax(atbPlotDetailService.updateAtbPlotDetail(atbPlotDetail));
    }

    /**
     * 修改小区状态
     */
    @PreAuthorize("@ss.hasPermi('plot:plot:edit')")
    @Log(title = "小区详情", businessType = BusinessType.UPDATE)
    @PutMapping("updateStatus")
    public AjaxResult updateStatus(@RequestBody StatusDto statusDto)
    {
        return toAjax(atbPlotDetailService.updateStatus(statusDto));
    }

    /**
     * 删除小区详情
     */
    @PreAuthorize("@ss.hasPermi('plot:plot:remove')")
    @Log(title = "小区详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{plotIds}")
    public AjaxResult remove(@PathVariable Long[] plotIds)
    {
        return toAjax(atbPlotDetailService.deleteAtbPlotDetailByPlotIds(plotIds));
    }
}
